<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>云校通-教师-家长调班申请</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left"> <a onclick="back()" href="javascript:;" class="icon icon-109 f-white">返回</a> </div>
	    	<h1 class="weui-header-title">${term.termName }</h1>
	    </div>
        <div class="weui_tab_bd">
            <div class="weui_tab kcfd-list1" id="tab3">
	            <div class="weui_navbar">
	                <div class="weui_navbar_item tab-blue">待处理(<span id="pendingCount"></span>)</div>
                    <div class="weui_navbar_item">已处理</div>
	            </div>
	            <div class="weui_tab_bd">
		            <div class="weui_panel weui_tab_bd_item afterNone qingjia mt0 pb55">
		            	<div class="weui_panel_bd">
	                    	<div class="weui_media_box weui_media_small_appmsg" id="pendingList">
			                </div>  
			            </div>
			        </div>
		            <div class="weui_panel weui_tab_bd_item qingjia mt0 pb55">
		            	<div class="weui_panel_bd">
	                    	<div class="weui_media_box weui_media_small_appmsg" id="auditedList">
			                </div>  
			            </div>
						<div class="dropload-down">
				        	<div class="loadData dropload-hasData">点击加载更多数据...</div>
				        </div>
			        </div>
	            </div>
	        </div>
	      </div> 
    </div>
    
    <div style="display:none;" id="weui_mask" class="weui_mask weui_mask_visible" style="transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);"></div>
	<div style="display:none;" id="weui_dialog" class="weui_dialog weui_dialog_visible" style="transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);">
		<div class="weui_dialog_hd">
			<strong class="weui_dialog_title">请输入驳回的原因</strong>
		</div>
		<div class="weui_dialog_bd">
			<textarea class="weui_input weui-prompt-input" style="height: 80px;width: 95%;" rows="10" id="rejectText"></textarea>
		</div>
		<div class="weui_dialog_ft">
			<a href="javascript:;" id="rejectCancel" class="weui_btn_dialog default">取消</a>
			<a href="javascript:;" id="rejectSure" class="weui_btn_dialog primary">确定</a>
		</div>
	</div>
</body>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script type="text/javascript">
var page = 1;
var rows = 10;
$(function(){
    $('#tab3').tab({
		defaultIndex: 0,
		activeClass: "tab-blue "
	});
    $("#tab3 .weui_navbar_item").click(function() {
    	var index = $(this).index();
    	if(index == 1) loadAuditedlist(false);
    })
    $(".dropload-down").on("click", ".dropload-hasData", function() {
    	loadAuditedlist(false);
    });
    loadPendinglist();
})

function loadPendinglist() {
	 $.ajax({
		url : basePath + "/ls/kccs/course/changeClass/pending",
		type : "post",
		dataType : "json",
		async : false,
		success : function(data) {
			if(data != null) {
				$("#pendingCount").html(data.length);
				var html = '';
				for(var i in data) {
					html += '<div class="weui_cells weui_cells_1">\
								<div class="weui_cell">\
							<div class="weui_cell_bd weui_cell_primary">\
								<p>'+data[i].studentName+'</p>\
							</div>\
							<div class="weui_cell_ft">\
								<img style="width: 60px" src="<%=basePath%>/images/daish.png">\
							</div>\
						</div>\
						<div class="weui_cell">\
							<div class="weui_cell_bd weui_cell_primary">\
								<p>已报课程</p>\
							</div>\
							<div class="weui_cell_ft"><a href="<%=basePath%>/ls/kccs/course/detail/'+data[i].oldCourseId+'?nt=query">'+data[i].oldCourseName+'</a></div>\
						</div>\
						<div class="weui_cell">\
							<div class="weui_cell_bd weui_cell_primary">\
								<p>申请课程</p>\
							</div>\
							<div class="weui_cell_ft"><a href="<%=basePath%>/ls/kccs/course/detail/'+data[i].newCourseId+'?nt=query">'+data[i].newCourseName+'</a></div>\
						</div>\
						<div class="weui_cell">\
							<div class="weui_cell_bd weui_cell_primary">\
								<p>申请时间</p>\
							</div>\
							<div class="weui_cell_ft">'+getTime(data[i].createTime,'yyyy-MM-dd hh:mm')+'</div>\
						</div>\
						<div class="weui_cell">\
							<button onclick="rejectSubmit('+data[i].reqId+')" class="weui_btn weui_btn_mini weui_btn_default">驳回调班</button>\
							<button onclick="agreeSubmit('+data[i].reqId+')" class="weui_btn_1 weui_btn weui_btn_mini bg-blue">同意调班</button>\
						</div>\
					</div>';
				}
				$("#pendingList").html(html);
			}
		}, error:function(){
		}
	});
}
function loadAuditedlist(reload) {
	 $.ajax({
		url : basePath + "/ls/kccs/course/changeClass/audied",
		type : "post",
		dataType : "json",
		data: {
			page: page,
			rows: rows
		},
		async : false,
		success : function(data) {
			if(data != null) {
				if(data.rows.length == 0 || page*rows >= data.total) {// 如果没有数据
           		 	 $("#auditedList").closest(".weui_tab_bd_item").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
                	 if(data.rows.length == 0) return;
                }
				page += 1;
				var html = '';
				for(var i in data.rows) {
					var itm = data.rows[i];
					html += '<div class="weui_cells weui_cells_1">\
								<div class="weui_cell">\
							<div class="weui_cell_bd weui_cell_primary">\
								<p>'+itm.studentName+'</p>\
							</div>\
							<div class="weui_cell_ft">\
								<img style="width: 60px" src="<%=basePath%>/images/'+(itm.status == '000' ? 'shenpitongguo.png' : 'shenpibohui.png')+'">\
							</div>\
						</div>\
						<div class="weui_cell">\
							<div class="weui_cell_bd weui_cell_primary">\
								<p>新选报课程</p>\
							</div>\
							<div class="weui_cell_ft"><a href="<%=basePath%>/ls/kccs/course/detail/'+itm.newCourseId+'?nt=query">'+itm.newCourseName+'</a></div>\
						</div>\
						<div class="weui_cell">\
							<div class="weui_cell_bd weui_cell_primary">\
								<p>原选报课程</p>\
							</div>\
							<div class="weui_cell_ft"><a href="<%=basePath%>/ls/kccs/course/detail/'+itm.oldCourseId+'?nt=query">'+itm.oldCourseName+'</a></div>\
						</div>\
						<div class="weui_cell">\
							<div class="weui_cell_bd weui_cell_primary">\
								<p>审批时间</p>\
							</div>\
							<div class="weui_cell_ft">'+getTime(itm.updateTime,'yyyy-MM-dd hh:mm')+'</div>\
						</div>\
						<div class="weui_cell">\
							<div class="weui_cell_bd weui_cell_primary"><p>驳回原因：</p></div>\
						</div>\
						<div class="weui_cell_1 weui_cell">\
							<p class="f15">'+itm.rejectReason+'</p>\
						</div>\
					</div>';
				}
				if(reload) $("#auditedList").html(html);
				else $("#auditedList").append(html);
			}
		}, error:function(){
		}
	});
}
function agreeSubmit(id) {
	$.confirm("是否与两个课程老师协商好同意调班?", "确认同意?", function() {
		$.ajax({
	      	url : basePath + "/ls/kccs/course/audit/success",
	 		type : "post",
	 		dataType : "json",
	 		data : {
	 			id: id
	 		},
	        success: function(data){
	        	if(data.code == '000') {
	        		$.toast("操作成功");
	        		loadPendinglist();
	        		return;
	        	}
	        	$.toptips("提交失败，请联系管理员");
	        },
	        error: function(xhr, type){
	        }
	     });
    }, function() {
      //取消操作
    });
}
function rejectSubmit(id) {
	var id = id;
	$(".weui_mask").addClass("weui_mask_visible").show();
	$(".weui_dialog").addClass("weui_dialog_visible").show();
	$("#rejectCancel").click(function(){
		$("#rejectText").val(null);
		$("#weui_mask").hide();
		$("#weui_dialog").hide();
	});
	$("#rejectSure").click(function(){
		var text = $("#rejectText").val();
		if(text.trim().length > 0) {
      		$.ajax({
    	      	url : basePath + "/ls/kccs/course/audit/reject",
    	 		type : "post",
    	 		dataType : "json",
    	 		data : {
    	 			id: id,
          			rejectReason: text
    	 		},
    	        success: function(data){
    	        	if(data.code == '000') {
    	        		$("#weui_mask").hide();
    	        		$("#weui_dialog").hide();
    	        		$.toast("操作成功");
    	        		setTimeout(window.location.reload(), 1000);
    	        	}else {
    	        		$.toptips("提交失败，请联系管理员");
    	        	}
    	        },
    	        error: function(xhr, type){
    	        }
    	     });
      	}
	});
}
</script>
</html>